<template>
    <div class="order-list" v-loading="loading">
        <div class="input-box">
            <span class="input-title">皮肤</span>
            <el-select v-model="paramsList.skinId" clearable style="width:200px;" filterable :filter-method="filterTrigger" @change="skinChange">
                <el-option :label="`${skinItem.name} - ${skinItem.heroName}`" :value="skinItem.skinId" v-for="skinItem in skinList" :key="skinItem.skinId"></el-option>
            </el-select>
            <span class="input-title" style="margin-left: 20px;">未匹配原因</span>
            <el-input
                placeholder="请输入未匹配原因"
                @keyup.enter.native="getList(1, 10)"
                style="width:200px;"
                clearable
                v-model.trim="paramsList.keyWord">
            </el-input>
            <el-button type="primary" class="btn" style="margin-left:20px" @click="getList(1)">查询</el-button>
            <el-button type="success" class="btn" style="margin-left:20px" @click="exportOrder">导出</el-button>
        </div>
        <div class="table-box">
            <el-table :data="tableData" ref="table" border style="width: 100%">
                <el-table-column width="200" prop="nickName" label="趣游戏用户">
                    <template slot-scope="scope">
                        <p>昵称：{{ scope.row.nickName }}</p>
                        <p>ID：{{ scope.row.userId }}</p>
                        <p>系统：{{ scope.row.areaType === 1 ? '安卓' : 'IOS' }}</p>
                    </template>
                </el-table-column>
                <el-table-column width="180" prop="month" label="预下单时间">
                    <template slot-scope="scope">{{ tableFormatDate(scope.row.createTime) }}</template>
                </el-table-column>
                <el-table-column label="下单明细">
                    <el-table-column prop="tradeAccountSelectRecord.hourDesc" label="时长" min-width="120"></el-table-column>
                    <el-table-column prop="city" label="所选皮肤" min-width="150">
                        <template slot-scope="scope">
                            <span v-for="(item, index) in scope.row.tradeAccountSelectRecord.skinPriceDescList" :key="index">
                                <i v-if="index > 0">，</i>{{ item }}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="address" label="段位" min-width="120">
                        <template slot-scope="scope">
                            <span v-for="(item, index) in scope.row.tradeAccountSelectRecord.jobList" :key="index">
                                <i v-if="index > 0">，</i>{{ item }}
                            </span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column min-width="100" label="未匹配原因" prop="tradeAccountSelectRecord.noMatchReason"></el-table-column>
            </el-table>
        </div>
        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'

export default {
    data () {
        return {
            pageNum: 1,
            pageSize: this._pageSize,
            paramsList: {},
            tableData: [],
            skinList: [],
            total: 0,
            loading: false
        }
    },
    created () {
        this.getList(1)
    },
    methods: {
        // 获取列表
        async getList (pageNum) {
            this.pageNum = pageNum
            if (this.loading) return
            this.loading = true
            let params = {
                pageNum,
                pageSize: this.pageSize
            }
            params = Object.assign(params, this.paramsList)
            let res = await this.$http.get('/trade/unMatchTradeOrders', {
                params
            })
            if (res.code === '0') {
                this.tableData = res.data
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },
        exportOrder () {
            let params = Object.assign({
                pageNum: this.pageNum,
                pageSize: this.pageSize
            }, this.paramsList)
            this.$http.post('/trade/exportUnMatchTradeOrders', params, {
                responseType: 'arraybuffer'
            }).then(res => {
                const aLink = document.createElement('a')
                let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
                aLink.href = URL.createObjectURL(blob)
                aLink.setAttribute('download', '未匹配订单' + '.xlsx') // 设置下载文件名称
                aLink.click()
            })
        },
        skinChange () {
            this.getList(1, 10)
        },
        filterTrigger (keyWord) {
            this.$http.get('/trade/selectWZRYSkin', {
                params: {
                    pageNum: 1,
                    pageSize: 999,
                    keyWord
                }
            }).then(res => {
                if (res.code === '0') {
                    this.skinList = res.data
                } else {
                    this.$message({
                        type: 'error',
                        message: '系统异常，请稍后再试'
                    })
                }
            })
        },
        // 页码切换
        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getList(1)
        },

        // 页容切换
        pageChange (val) {
            this.pageNum = val
            this.getList(this.pageNum)
        },
        tableFormatDate (timestamp, type = 'YYYY-MM-DD') {
            return formatDate(timestamp, type)
        }
    }
}
</script>

<style lang="scss" scoped>
    .order-list {
        .table-box {
            margin: 20px 0;
        }
        .input-box {
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin: 0 10px 0 0px;
            }
            .btn {
                margin-top: 10px;
                margin-left: 10px;
            }
        }
        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
</style>
